package com.ywb.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;


//
public class MyLocaleResolver implements LocaleResolver {
    //处理地区
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String language = httpServletRequest.getParameter("language");
        Locale myLocale = Locale.getDefault();
        if (!StringUtils.isEmpty(language)) {
            String[] locales = language.split("_");
            myLocale = new Locale(locales[0], locales[1]);
        }
        return myLocale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
